package com.xiaoy.core.tag;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.BodyTagSupport;

import com.xiaoy.core.tag.html.GridColumnHtml;



public class GridColumnTag extends BodyTagSupport {
	
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	


	@Override
	public int doStartTag() throws JspException {
		
		GridDataTag gridData = getGridDataTag();
		GridColumnHtml html = new GridColumnHtml();
		html.setName(name);
		html.setTitle(title);
		gridData.addColumnHtmls(html);
//		if (!gridData.isEmpty()) {
//			try {
//				List dataList = gridData.getDataList();
//				Iterator it = dataList.iterator();
//				
//				JspWriter out = pageContext.getOut();
//				while (it.hasNext()) {
//					Object obj = it.next();
//					out.write("col-->" + obj + "<br/>");
//					System.out.println("col-->" + obj + "<br/>");
//				}
//				while (it.hasNext()) {
//					
//					Object obj = it.next();
//					bodyContent.write("col-->" + obj + "<br/>");
//					System.out.println("col-->" + obj + "<br/>");
//				}
//			} catch (Exception e) {
//				e.printStackTrace();
//			}
//		}
		
//		if (gridData.isEmpty() || !gridData.isIncludedRow()){
//            return SKIP_BODY;
//        }
		
		return EVAL_BODY_INCLUDE;
	}
	
    protected GridDataTag getGridDataTag(){
    
        return (GridDataTag) findAncestorWithClass(this, GridDataTag.class);
    }
	

    
    
    
    //--------------------------
    
    private String name;
    private String title;



	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getTitle() {
		if (title==null||"".equals(title)) {
			return name;
		}
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}
	
    
	
}